package com.tsd.shiro.config;

import com.tsd.core.shiro.IShiroConst;
import com.tsd.core.shiro.config.ShiroAuthToken;
import com.tsd.system.entity.SysUserExt;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

/**
 * @ClassName: ShiroCredentialsMatcher
 * @Description: TODO
 * @Author: Hillpool
 * @Date: 2022/7/15 12:31
 * @Version: 1.0
 */
public class ShiroCredentialsMatcher extends SimpleCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        ShiroAuthToken authToken = (ShiroAuthToken) token;
        if (IShiroConst.REALM_NAME_TOKEN.equals(authToken.getLogin_type())) {
            return true;
        }
        if (IShiroConst.REALM_NAME_SYS_USER.equals(authToken.getLogin_type())) {
            SysUserExt userExt = (SysUserExt) getCredentials(info);
            return authToken.getUsername().equals(userExt.getLogin_id());
        }
        return false;
    }
}
